<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 */
namespace app\index\domain;

use app\index\domain\BaseDomain;
use app\bbs\api\BbsMemberApi;
use app\system\api\MemberApi;
use app\shop\api\MemberConfigApi;
use app\system\api\MemberFocusApi;
use app\bbs\api\ForumAttachmentApi;
use app\bbs\api\ForumPostApi;
use app\bbs\api\ForumForumApi;
use app\bbs\api\TagApi;
use app\bbs\api\ForumPostcommentApi;
use app\bbs\api\ForumPostLikeApi;
use app\bbs\api\ForumThreadApi;
use app\bbs\model\ForumPost;
use app\system\api\BabyApi;
use app\shop\api\OrderCommentApi;
use app\shop\api\OrdersItemApi;
use app\shop\api\OrderCommentAttachsApi;
use app\shop\api\FavoritesApi;
use app\shop\api\WalletApi;
use app\shop\api\WalletApplyApi;
use app\shop\api\WithdrawAccountApi;
use app\shop\model\WithdrawAccount;
use app\shop\api\MmzWinnerPepoleApi;
use app\shop\api\MmzImageApi;
use app\shop\api\AddressApi;

class BbsUserCenterDomain extends BaseDomain{
    protected $business_code = 'BbsMyCenter';
    //取消收藏 - 多选 或 单选
    public function fav(){
        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("BbsUserCenter/fav",$_GET,$_POST,"应用" . $this->client_id . "调用取消收藏接口");
            // $this->apiReturnErr(I('post.'));
            $uid  = $this->_post('uid',0,'用户ID缺失');
            $ids  = $this->_post('ids','','ids缺失');
            $type = $this->_post('fav_type','','fav_type缺失');
            if(!in_array(intval($type), [1,2,3]))  $this->apiReturnErr('类型错误');
            $ids = explode(',', $ids);
            $model = new \think\model\Adv();
            $model ->startTrans();
            foreach ($ids as $v) {
                $r = apiCall(FavoritesApi::DELETE,[['type'=>$type,'favorite_id'=>$v,'uid'=>$uid]]);
                if(!$r['status']){
                    $model ->rollback();
                    $this->apiReturnErr($r['info']);
                }
            }
            $model ->commit();
            $this->apiReturnSuc('取消收藏成功！');
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    //提现记录
    public function walletLog(){
        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("BbsUserCenter/walletOut",$_GET,$_POST,"应用" . $this->client_id . "调用申请提现接口");
            $uid      = $this->_post('uid',0,'用户ID缺失');
            $log_type = $this->_post('log_type',-1);
            $pageNo   = $this->_post('page_no',1);
            $pageSize = $this->_post('page_size',10);
            if(!in_array($log_type, [-1,0,1,2]))  $this->apiReturnErr('类型错误');
            $map = ['uid'=>$uid];
            if($log_type !== -1) $map['valid_status'] = $log_type;
            $r = apiCall(WalletApplyApi::QUERY_WITH_COUNT,[$map,['curpage'=>$pageNo,'size'=>$pageSize],'create_time desc',$map,'create_time,money,valid_status,reply_msg,reason']);
            if(!$r['status']) $this->apiReturnErr($r['info']);
            $this->apiReturnSuc($r['info']);
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    //申请提现
    public function walletOut(){
        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("BbsUserCenter/walletOut",$_GET,$_POST,"应用" . $this->client_id . "调用申请提现接口");
            $uid   = $this->_post('uid',0,'用户ID缺失');
            $money = $this->_post('money',0,'提现金额错误');
            $uid   = intval($uid);
            $money = intval($money);
            if($money<=0)  $this->apiReturnErr('提现金额错误');
            //是否有未处理的申请
            $r = apiCall(WalletApplyApi::GET_INFO,[['uid'=>$uid,'valid_status'=>0]]);
            if(!$r['status']) $this->apiReturnErr($r['info']);
            if($r['info']) $this->apiReturnErr('请等待上次申请结果...');
            //查寻用户可余额
            $r = apiCall(WalletApi::GET_INFO,[['uid'=>$uid],false,'account_balance,frozen_funds']);
            if(!$r['status']) $this->apiReturnErr($r['info']);
            if(empty($r['info'])) $this->apiReturnErr('用户余额不足');
            $after = intval($r['info']['account_balance']) - intval($r['info']['frozen_funds']);
            if($after<=0 || $after<$money) $this->apiReturnErr('余额不足');
            //写入申请记录
            $now = time();
            $map = [
                'create_time'  => $now,
                'reason'       => '提现',
                'uid'          => $uid,
                'reply_msg'    => '',
                'money'        => $money,
                'valid_status' => 0
            ];
            $r = apiCall(WalletApplyApi::ADD,[$map]);
            if(!$r['status']) $this->apiReturnErr($r['info']);
            $this->apiReturnSuc('申请成功');
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    //我的MMZ商品评价 - 分页
    public function giftComment(){
        if(IS_POST){
            $this->checkVersion(100);
            addLog("BbsUserCenter/giftComment",$_GET,$_POST,"应用" . $this->client_id . "调用我的MMZ评价查询接口");
            $uid      = $this->_post('uid',0,'用户ID缺失');
            $pageNo   = $this->_post('page_no',1);
            $pageSize = $this->_post('page_size',10);
            $max_img  = $this->_post("max_img",3);
            $max_img  = max(0,intval($max_img));
            $r = apiCall(MmzWinnerPepoleApi::QUERY_WITH_PRO,[['wp.uid'=>$uid,'_string'=>'wp.evaluate_time > 0'],['curpage'=>$pageNo,'size'=>$pageSize],'wp.evaluate_time desc',false,'wp.*,cm.head,cm.nickname']);
            if(!$r['status']) $this->apiReturnErr($r['info']);
            foreach ($r['info']['list'] as &$v) {
                //查询评价图片
                $res = apiCall(MmzImageApi::QUERY,[['goods_id'=>$v['goods_id']],['curpage'=>1,'size'=>$max_img],'id asc',false,'img_id']);
                if(!$res['status']) $this->apiReturnErr($res['info']);
                $v['evaluate_imgs'] = [];
                foreach ($res['info']['list'] as $vv) {
                    $v['evaluate_imgs'][] = $vv['img_id'];
                }
            }
            $this->apiReturnSuc($r['info']);
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    //我的商品评价 - 分页
    public function proComment(){
        if(IS_POST){
            $this->checkVersion(101);
            addLog("BbsUserCenter/proComment",$_GET,$_POST,"应用" . $this->client_id . "调用我的商品评价查询接口");
            $uid      = $this->_post('uid',0,'用户ID缺失');
            $pageNo   = $this->_post('page_no',1);
            $pageSize = $this->_post('page_size',10);
            $max_img  = $this->_post("max_img",3);
            // $fields = 'id,user_id,score,comment,product_id,order_code';
            $result   = apiCall(OrderCommentApi::QUERY_WITH_COUNT,[['user_id'=>$uid],['curpage'=>$pageNo,'size'=>$pageSize],'createtime desc']);
            if(!$result['status']) $this->apiReturnErr($result['info']);
            foreach ($result['info']['list'] as &$v) {
                // order_code id product_id user_id
                // 查询规格
                $r = apiCall(OrdersItemApi::GET_INFO,[['p_id'=>$v['product_id'],'order_code'=>$v['order_code']]]);
                $info = $r['info'];
                if(!$r['status']) $this->apiReturnErr($info);
                if(empty($info)){
                    $v['sku_info'] = [];
                }else{
                    $v['sku_info'] = [
                        'id'         =>$info['id'],
                        'name'       =>$info['name'],
                        'img'        =>$info['img'],
                        'sku_id'     =>$info['sku_id'],
                        'sku_desc'   =>$info['sku_desc'],
                        'count'      =>$info['count'],
                        'createtime' =>$info['createtime'],
                    ];
                }
                // $map = ['order_code'=>$v['order_code'],'p_id'=>$v['product_id']];
                // $res = apiCall(OrdersItemApi::GET_INFO,[$map,false,['img,sku_desc']]);
                // if($res['status']){
                //     $v['product_img'] = $res['info']['img'];
                //     $v['product_sku'] = $res['info']['sku_desc'];
                // }else{
                //     $this -> apiReturnErr($res['info']);
                // }
                // 查询用户信息
                $userInfo = $this->getUserInfo2($v['user_id']);
                // trace($userInfo);
                $v['user_head'] = empty($userInfo) ? '' : $userInfo['head'];
                $v['user_nick'] = empty($userInfo) ? '' : $userInfo['nickname'];
                $v['user_sex']  = empty($userInfo) ? '' : $userInfo['sex'];
                unset($userInfo);
                //查询附件信息
                $map = ['comment_id'=>$v['id']];
                $res = apiCall(OrderCommentAttachsApi::QUERY_NO_PAGING,[$map,false,['pic_id']]);
                if($res['status']){
                    $v['img'] = [];
                    $i = 0;
                    foreach($res['info'] as $vv){
                        if($i >$max_img) break;
                        array_push($v['img'],$vv['pic_id']);
                        $i++;
                    }
                }else{
                    $this -> apiReturnErr($res['info']);
                }
            }
            $this->apiReturnSuc($result['info']);
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }

    //点赞我的 - 分页
    public function likeMe(){
        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("BbsUserCenter/likeMe",$_GET,$_POST,"应用" . $this->client_id . "调用点赞我的查询接口");

            $uid      = $this->_post('uid',0,'用户ID缺失');
            $pageNo   = $this->_post('page_no',1);
            $pageSize = $this->_post('page_size',10);
            $result = apiCall(ForumPostLikeApi::QUERY_WITH_USER,[['p.author_id'=>$uid,'t.status'=>0],['curpage'=>$pageNo,'size'=>$pageSize],'like_time desc',false,'p.*,m.head,m.nickname,m.sign,t.message,t.fid']);
            // $this->apiReturnErr($result['info']);
            if($result['status']){
                $count = $result['info']['count'];
                $list  = $result['info']['list'];
                // foreach ($list as &$v) {
                  //查询用户信息
                  // $userInfo = $this->getUserInfo2($v['uid']);
                  // $v['head']     = empty($userInfo) ? '' : $userInfo['head'];
                  // $v['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                  // $v['sign']     = empty($userInfo) ? '' : $userInfo['sign'];
                  //我是否关注过
                  // $v['is_focus_back'] = '0';
                  // if($my_uid){
                  //     $result = apiCall(MemberFocusApi::GET_INFO,[['uid'=>$my_uid,'focus_uid'=>$v['uid']]]);
                  //     if(!$result['status']) $this->apiReturnErr($result['info']);
                  //     $v['is_focus_back'] = empty($result['info'])?'0':'1';
                  // }
                  // $v['uid'] = $v['uid'];
                  // unset($v['focus_uid']);
                // }
                $this->apiReturnSuc(['count'=>$count,'list'=>$list]);
            }else{
                $this->apiReturnErr($result['info']);
            }
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    //粉丝列表 - 分页
    public function focusMe(){
        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("BbsUserCenter/focusMe",$_GET,$_POST,"应用" . $this->client_id . "调用关注我的查询接口");

            $uid      = $this->_post('uid',0,'用户ID缺失');
            $my_uid   = $this->_post('my_uid','');
            $pageNo   = $this->_post('page_no',1);
            $pageSize = $this->_post('page_size',10);
            $result = apiCall(MemberFocusApi::QUERY_WITH_COUNT,[['focus_uid'=>$uid],['curpage'=>$pageNo,'size'=>$pageSize],'focus_time desc']);
            // $this->apiReturnErr($result['info']);
            if($result['status']){
                $count = $result['info']['count'];
                $list  = $result['info']['list'];
                foreach ($list as &$v) {
                  //查询用户信息
                  $userInfo = $this->getUserInfo2($v['uid']);
                  $v['sex']      = empty($userInfo) ? '' : $userInfo['sex'];
                  $v['head']     = empty($userInfo) ? '' : $userInfo['head'];
                  $v['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                  $v['sign']     = empty($userInfo) ? '' : $userInfo['sign'];
                  //我是否关注过
                  $v['is_focus_back'] = '0';
                  if($my_uid){
                      $result = apiCall(MemberFocusApi::GET_INFO,[['uid'=>$my_uid,'focus_uid'=>$v['uid']]]);
                      if(!$result['status']) $this->apiReturnErr($result['info']);
                      $v['is_focus_back'] = empty($result['info'])?'0':'1';
                  }
                  // $v['uid'] = $v['uid'];
                  unset($v['focus_uid']);
                }
                $this->apiReturnSuc(['count'=>$count,'list'=>$list]);
            }else{
                $this->apiReturnErr($result['info']);
            }
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    //关注列表 - 分页
    public function myFocus(){
        if(IS_POST){
            $this->checkVersion($this->api_ver);
            addLog("BbsUserCenter/myFocus",$_GET,$_POST,"应用" . $this->client_id . "调用我的关注查询接口");

            $uid      = $this->_post('uid',0,'用户ID缺失');
            $my_uid   = $this->_post('my_uid','');
            $pageNo   = $this->_post('page_no',1);
            $pageSize = $this->_post('page_size',10);
            $result = apiCall(MemberFocusApi::QUERY_WITH_COUNT,[['uid'=>$uid],['curpage'=>$pageNo,'size'=>$pageSize],'focus_time desc']);
            // $this->apiReturnErr($result['info']);
            if($result['status']){
                $count = $result['info']['count'];
                $list  = $result['info']['list'];
                foreach ($list as &$v) {
                  //查询用户信息
                  $userInfo  = $this->getUserInfo2($v['focus_uid']);
                  $v['head']     = empty($userInfo) ? '' : $userInfo['head'];
                  $v['sex']      = empty($userInfo) ? '' : $userInfo['sex'];
                  $v['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                  $v['uid']      = $v['focus_uid'];
                  $v['sign']     = empty($userInfo) ? '' : $userInfo['sign'];
                  //我是否关注过
                  $v['is_focus_back'] = '0';
                  if($my_uid){
                      $result = apiCall(MemberFocusApi::GET_INFO,[['uid'=>$my_uid,'focus_uid'=>$v['focus_uid']]]);
                      if(!$result['status']) $this->apiReturnErr($result['info']);
                      $v['is_focus_back'] = empty($result['info'])?'0':'1';
                  }
                  unset($v['focus_uid']);
                }
                $this->apiReturnSuc(['count'=>$count,'list'=>$list]);
            }else{
                $this->apiReturnErr($result['info']);
            }
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }

    //api - 个人信息
    public function getUserInfo(){

        if(IS_POST){
            $this->checkVersion(101);
            addLog("BbsUserCenter/getUserInfo",$_GET,$_POST,"应用" . $this->client_id . "调用用户信息查询接口");

            $uid      = $this->_post('uid','','用户ID缺失');
            $from_uid = $this->_post('from_uid','');
            $result   = $this->userInfo($uid);
            if($result['status']){
                $uinfo = $result['info'];
                // trace('---uinfo');
                // trace($uinfo);
                if(empty($uinfo)) $this->apiReturnSuc([]);
                //是否关注了uid
                $uinfo['is_focus'] = '0';
                if($from_uid){
                    $r = apiCall(MemberFocusApi::GET_INFO,[['uid'=>$from_uid,'focus_uid'=>$uid]]);
                    if(!$r['status']) $this->apiReturnErr($r['info']);
                    if(!empty($r['info'])) $uinfo['is_focus'] = '1';
                }
                //查询支付宝帐号
                $uinfo['alipay'] = '';
                $uinfo['alipay_status'] = '-1';
                // $r = apiCall(MemberConfigApi::GET_INFO,[['uid'=>$uid],false,'alipay_account']);
                // if(!$r['status']) $this->apiReturnErr($r['info']);
                // if($r['info']) $uinfo['alipay'] = $r['info']['alipay_account'];
                $r = apiCall(WithdrawAccountApi::GET_INFO,[['uid'=>$uid,'account_type'=>WithdrawAccount::ALIPAY]]);
                if(!$r['status']) $this->apiReturnErr($r['info']);
                if(!empty($r['info'])){
                   $uinfo['alipay'] = $r['info']['account'];
                   $uinfo['alipay_status'] = $r['info']['valid_status'];
                }
                //查询经验。积分
                //查询零钱
                $r = apiCall(WalletApi::GET_INFO,[['uid'=>$uid],false,'account_balance,frozen_funds']);
                if($r['status']){
                    $uinfo['balance'] = '0.00';
                    $uinfo['balance_frozen'] = '0.00';
                    if($r['info']){
                        $uinfo['balance'] = $r['info']['account_balance'];
                        $user_info['balance_frozen'] = $r['info']['frozen_funds'];
                    }
                }else{
                    $this->apiReturnErr($result['info']);
                }
                //查询用户默认地址
                $aid = $this->getAidByUid($uid);
                if($aid){
                    $map = ['uid' => $uid,'id'=>$aid];
                    $r   = apiCall(AddressApi::GET_INFO,[$map]);
                }else{
                    $map = ['uid' => $uid];
                    $r   = apiCall(AddressApi::GET_INFO,[$map,'id desc',false,true]);
                }
                if(!$r['status']) $this->apiReturnErr($r['info']);
                $uinfo['address_default'] = $r['info'];
                //查询默认宝宝信息
                $uinfo['baby_default'] = apiCall(BabyApi::GET_DEFAULT,[$uid]);
                //私信信息
                // $r = apiCall(MessageBoxApi::COUNT,[['uid']]);
                $this->apiReturnSuc($uinfo);
            }else{
                $this->apiReturnErr($result['info']);
            }
        }else{
            $this->apiReturnErr('只支持POST请求');
        }
    }
    private function getAidByUid($uid=0){
        $result = apiCall(MemberConfigApi::GET_INFO,[['uid'=>$uid]]);
        if(false === $result['status'])
            $this->apiReturnErr('系统错误: 获取用户配置失败！');
        return empty($result['info'])?0:intval($result['info']['default_address']);
    }
    public function userInfo($uid,&$arr=null){
        $result = apiCall(BbsMemberApi::GET_USER_INFO,array($uid));
        if(!is_null($arr) && $result['status']){
            $arr['user_info'] = $result['info'];
        }
        return $result;

    }
    //我的帖子 - 分页
    public function queryThread(){

        $this->checkVersion($this->api_ver);
        addLog("BbsUserCenter/queryThread",$_GET,$_POST,"应用" . $this->client_id . "调用我的帖子查询接口");
        if(IS_POST){
            $uid       = $this -> _post('uid',0,'用户id缺失');
            $fid       = $this -> _post('fid',0);
            $page_no   = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',10);
            $img_num   = $this -> _post('img_num',3);
            $max_like    = $this -> _post('max_like',10);
            $max_reply   = $this -> _post('max_reply',3);
            $max_comment = $this -> _post('max_comment',2);

            $order  = "dateline desc";
            $map = ['uid'=>$uid,'num'=>$img_num];
             if($fid){
                $r = apiCall(ForumForumApi::GET_FID_WITH_CHILD,[$fid]);
                if(!$r['status']) return $this->apiReturnErr($r['info']);
                if($r['info']) $map['_string'] = 'fid in ('.implode(',', $r['info']).')';
            }
            $result = apiCall(ForumThreadApi::MY_THREADS,[$map,$page_no,$page_size,$order]);
            if($result['status']){
                $count = $result['info']['count'];
                $list  = $result['info']['list'];
                foreach($list as &$v){
                    unset($v['position']);
                    //标签信息
                    $v['tag_info'] = apiCall(TagApi::GET_S,[$v['tid']]);
                    //宝宝信息
                    $v['baby_default'] = apiCall(BabyApi::GET_DEFAULT,[$v['author_id']]);
                    //点赞信息
                    $v['like_info'] = [];
                    if(intval($max_like)>0){
                        $r = apiCall(ForumPostLikeApi::QUERY_WITH_USER,[['p.tid'=>$v['tid']],['curpage'=>1,'size'=>$max_like],false,false,'p.id,p.uid,p.like_time,m.head,m.nickname']);
                        if(!$r['status']) $this->apiReturnErr($r['info']);
                        $v['like_info'] = $r['info']['list'];
                    }
                    //获取回复信息 - 自带评论
                    $result = apiCall(ForumPostApi::QUERY_POST,array($v['fid'],$v['tid'],1,$max_reply,$max_comment,0));
                    if(!$result['status']) $this -> apiReturnErr($result['info']);
                    $v['reply_info'] = $result['info'];
                }
                $this -> apiReturnSuc(['count'=>$count,'list'=>$list]);

            }else{
                $this -> apiReturnErr($result['info']);
            }
        }

    }
    //我的评论 - 去掉已删除的帖子
    //
    public function queryComment(){

        $this->checkVersion($this->api_ver);
        addLog("BbsUserCenter/queryComment",$_GET,$_POST,"应用" . $this->client_id . "调用我的评论查询接口");

        if(IS_POST){
            $uid       = $this -> _post('uid',0,'用户id缺失');
            $page_no   = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',10);
            $result = apiCall(ForumPostcommentApi::MY_COMMENTS,[$uid,$page_no,$page_size,'dateline desc']);
            if($result['status']){

                foreach($result['info']['list'] as &$vo) {
                    $time = time() - $vo['dateline'];
                    $vo['dateline_show'] = getDateInfo($time, $vo['dateline']);
                    //取用户信息
                    $userInfo = $this -> getUserInfo2($vo['author_id']);
                    $vo['author'] = empty($userInfo) ? '' : $userInfo['nickname'];
                    $vo['head']   = empty($userInfo) ? '' : $userInfo['head'];
                    $vo['sex']    = empty($userInfo) ? '' : $userInfo['sex'];
                    //帖子信息
                    $res  = apiCall(ForumThreadApi::GET_INFO,[['tid'=>$vo['tid']],false,'author_id,tid,fid,subject,message,status']);
                    if(!$res['status']) $this -> apiReturnErr($res['info']);
                    $vo['thread_info'] = $res['info'];
                    if(!empty($res['info'])){
                        $userInfo = $this -> getUserInfo2($res['info']['author_id']);
                        $vo['thread_info']['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                        $vo['thread_info']['head']     = empty($userInfo) ? '' : $userInfo['head'];
                        $vo['thread_info']['sex']      = empty($userInfo) ? '' : $userInfo['sex'];
                    }
                    //附件信息
                    $map = ['tid' => $vo['tid']];
                    $res = apiCall(ForumThreadApi::GET_INFO,array($map));
                    if($res['status']){
                        if($res['info'] == ""){
                            $this -> apiReturnErr("数据有误");
                        }else{
                            $vo['thread_status'] = $res['info']['status'];
                        }
                    }else{
                        $this -> apiReturnErr($res['info']);
                    }
                }

                $this -> apiReturnSuc($result['info']);
            }else{
                $this -> apiReturnErr($result['info']);
            }
        }

    }
    //我的回复
    public function queryPost(){

        $this->checkVersion($this->api_ver);
        addLog("BbsUserCenter/queryPost",$_GET,$_POST,"应用" . $this->client_id . "调用我的回复查询接口");

        if(IS_POST){
            $uid       = $this -> _post('uid',0,'用户id缺失');
            $page_no   = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',10);
            $img_num   = $this -> _post('img_num',3);
            $result = apiCall(ForumPostApi::MY_REPLY,[$uid,$page_no,$page_size,'dateline desc']);
            if($result['status']){
                foreach($result['info']['list'] as &$vo){
                    $time = time() - $vo['dateline'];
                    $vo['dateline_show'] = getDateInfo($time,$vo['dateline']);
                    //取用户信息
                    $userInfo = $this -> getUserInfo2($vo['author_id']);
                    $vo['author'] = empty($userInfo) ? '' : $userInfo['nickname'];
                    $vo['head']   = empty($userInfo) ? '' : $userInfo['head'];
                    $vo['sex']    = empty($userInfo) ? '' : $userInfo['sex'];
                    //帖子信息
                    $res  = apiCall(ForumThreadApi::GET_INFO,[['tid'=>$vo['tid']],false,'author_id,tid,fid,subject,message,status']);
                    if(!$res['status']) $this -> apiReturnErr($res['info']);
                    $vo['thread_info'] = $res['info'];
                    if(!empty($res['info'])){
                        $userInfo = $this -> getUserInfo2($res['info']['author_id']);
                        $vo['thread_info']['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                        $vo['thread_info']['head']     = empty($userInfo) ? '' : $userInfo['head'];
                        $vo['thread_info']['sex']      = empty($userInfo) ? '' : $userInfo['sex'];
                    }
                    //附件信息
                    $map = [
                        'tid' => $vo['tid'],
                    ];
                    $field = "aid";
                    $res   = apiCall(ForumAttachmentApi::QUERY_NO_PAGING,array($map,false,$field));
                    if($res['status']){
                        $vo['img'] = array();
                        $i = 0;
                        foreach($res['info'] as $v){
                            array_push($vo['img'],$v['aid']);
                            $i++;
                            if($i>=$img_num) break;
                        }
                    }else{
                        $this -> apiReturnErr($res['info']);
                    }
                }
                $this -> apiReturnSuc($result['info']);

            }else{
                $this -> apiReturnErr($result['info']);
            }
        }

    }

    //回复我的
    public function replyThread(){

        $this->checkVersion($this->api_ver);
        addLog("BbsUserCenter/replyThread",$_GET,$_POST,"应用" . $this->client_id . "调用查看主题回复接口");

        if(IS_POST){
            $uid       = $this -> _post('uid',0,'用户id缺失');
            $page_no   = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',10);
            $img_num   = $this -> _post('img_num',3);

            $result = apiCall(ForumPostApi::REPLY_ME,[$uid,$page_no,$page_size]);
            if($result['status']){
                foreach($result['info']['list'] as &$vo){
                    $time = time() - $vo['dateline'];
                    $vo['dateline_show'] = getDateInfo($time,$vo['dateline']);

                    //取用户信息
                    $userInfo = $this -> getUserInfo2($vo['author_id']);
                    $vo['author'] = empty($userInfo) ? '' : $userInfo['nickname'];
                    $vo['head']   = empty($userInfo) ? '' : $userInfo['head'];
                    $vo['sex']    = empty($userInfo) ? '' : $userInfo['sex'];
                    //帖子信息
                    $res  = apiCall(ForumThreadApi::GET_INFO,[['tid'=>$vo['tid']],false,'author_id,tid,fid,subject,message,status']);
                    if(!$res['status']) $this -> apiReturnErr($res['info']);
                    $vo['thread_info'] = $res['info'];
                    if(!empty($res['info'])){
                        $userInfo = $this -> getUserInfo2($res['info']['author_id']);
                        $vo['thread_info']['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                        $vo['thread_info']['head']     = empty($userInfo) ? '' : $userInfo['head'];
                        $vo['thread_info']['sex']      = empty($userInfo) ? '' : $userInfo['sex'];
                    }
                    //附件信息
                    $map = [
                        'tid' => $vo['tid'],
                    ];
                    $field = "aid";
                    $res = apiCall(ForumAttachmentApi::QUERY_NO_PAGING,array($map,false,$field));
                    if($res['status']){
                        $vo['img'] = [];
                        foreach($res['info'] as $v){
                            array_push($vo['img'],$v['aid']);
                        }
                    }else{
                        $this -> apiReturnErr($res['info']);
                    }
                }
                $this -> apiReturnSuc($result['info']);

            }else{
                $this -> apiReturnErr($result['info']);
            }
        }

    }
    //评论我的
    public function replyPost(){

        $this->checkVersion($this->api_ver);
        addLog("BbsUserCenter/replyPost",$_GET,$_POST,"应用" . $this->client_id . "调用查看帖子回复接口");

        if(IS_POST){
            $uid       = $this -> _post('uid',0,'用户id缺失');
            $page_no   = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',10);

            $result = apiCall(ForumPostApi::COMMENT_ME,[$uid,$page_no,$page_size]);
            if($result['status']){

                foreach($result['info']['list'] as &$vo) {
                    $time = time() - $vo['dateline'];
                    $vo['dateline_show'] = getDateInfo($time, $vo['dateline']);
                    //取用户信息
                    $userInfo     = $this -> getUserInfo2($vo['author_id']);
                    $vo['author'] = empty($userInfo) ? '' : $userInfo['nickname'];
                    $vo['head']   = empty($userInfo) ? '' : $userInfo['head'];
                    $vo['sex']    = empty($userInfo) ? '' : $userInfo['sex'];
                    //帖子信息
                    $res  = apiCall(ForumThreadApi::GET_INFO,[['tid'=>$vo['tid']],false,'author_id,tid,fid,subject,message,status']);
                    if(!$res['status']) $this -> apiReturnErr($res['info']);
                    $vo['thread_info'] = $res['info'];
                    if(!empty($res['info'])){
                        $userInfo = $this -> getUserInfo2($res['info']['author_id']);
                        $vo['thread_info']['nickname'] = empty($userInfo) ? '' : $userInfo['nickname'];
                        $vo['thread_info']['head']     = empty($userInfo) ? '' : $userInfo['head'];
                        $vo['thread_info']['sex']      = empty($userInfo) ? '' : $userInfo['sex'];
                    }
                    //附件信息
                    $map = [
                        'tid' => $vo['tid'],
                    ];
                    $res = apiCall(ForumThreadApi::GET_INFO,[$map]);
                    if($res['status']){
                        if($res['info'] == ""){
                            $this -> apiReturnErr("数据有误");
                        }else{
                            $vo['thread_status'] = $res['info']['status'];
                        }
                    }else{
                        $this -> apiReturnErr($res['info']);
                    }
                }

                $this -> apiReturnSuc($result['info']);
            }else{
                $this -> apiReturnErr($result['info']);
            }
        }

    }
    /**
     * 查询用户信息
     */
    private function getUserInfo2($uid){
        //$result = apiCall('Api/BbsUserCenter/userInfo',array($uid),'Domain');
        $result = apiCall(MemberApi::GET_INFO,[['uid'=>$uid]]);
        if($result['status'] && $result['info']){
            return $result['info'];
        }else{
            return [];//$this->apiReturnErr('查询用户信息失败');
        }
    }

}